/*
 * ============================================================================
 *                   GNU Lesser General Public License
 * ============================================================================
 *
 *
 *
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
 *
 *
 *
 */
package rad.framework.seam;

import java.util.Collection;

import rad.framework.richfaces.EntityTreeNode;
import rad.framework.richfaces.FolderTreeNode;
import rad.framework.richfaces.FolderTreeNode.CardinalityType;
import rad.framework.seam.RefEntityTreeNode.RefEntityFolderTreeNode;

import org.richfaces.model.TreeNode;

public class SampleEntityTreeNode extends EntityTreeNode<SampleEntity> {
	private static final long serialVersionUID = 1L;

	public SampleEntityTreeNode(TreeNode parent, SampleEntity entity) {
		super(parent, entity);
	}

	public String getText() {
		return getInstance().getName();
	}
	
	public SampleEntityEditor getSampleEntityEditor() {
		return (SampleEntityEditor) getEditor();
	}
	
	private FolderTreeNode childrenFolder = new RefEntityFolderTreeNode(this,
			"SampleEntity_children", CardinalityType.O2M) {
		protected void initNewInstance(RefEntity newInstance) {
			// newInstance.setSampleEntity(getInstance());
		}

		protected Collection<RefEntity> getCollection() {
			return getInstance().getChildren();
		}
	};

	// ------------------------------------------------------------------------
	// --- Folder Class
	// ------------------------------------------------------------------------

	public static class SampleEntityFolderTreeNode extends
			FolderTreeNode<SampleEntity> {

		public SampleEntityFolderTreeNode(TreeNode parent, String text, CardinalityType type) {
			super(parent, text, type);
		}

		public EntityTreeNode addChild(SampleEntity newInstance) {
			return new SampleEntityTreeNode(this, newInstance);
		}

		public void removeChild2(SampleEntity instance) {
			removeChild(instance.getId());
		}
	}
}
